<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./layui/css/layui.css">

</head>
<body class="layui-container">

    <div class="layui-row" style="margin-top:10%">
        <div class="layui-col-xs6 layui-col-md-offset2">
            <form class="layui-form" action="dologin" method="post" layui-filter="login">
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" lay-verify="text" autocomplete="off" placeholder="请输入账号"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="text" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="login" lay-filter="login">登陆</button>
                        <span id="msg"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
<script src="./layui/jquery-3.5.0.min.js"></script>
<script src="./layui/layui.js"></script>
<script type="text/javascript">


    layui.use(['form','layer'],function () {
        var form = layui.form;

        var layer = layui.layer;


        form.on('submit(login)',function (data) {
            console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}

            $.ajax({
                url:"sys/admin/login",
                type:'POST',
                data:data.field,
                success:function (result) {
                    if(result.state){   //如果登录成功
                        location.href="index.html";
                    }else {
                        layer.msg(result.message,{icon:5});  //登录失败
                    }
                }
            });
            return false;
        });
    })
</script>
</body>
</html>